{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">工资录入</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <th class="layui-td-gray">月份</th>
            <th class="layui-td-gray">员工姓名</th>
            <th class="layui-td-gray">工时</th>
            <th class="layui-td-gray">工资(元)</th>
            <th class="layui-td-gray">社保(元)</th>
            <th class="layui-td-gray">公积金(元)</th>
        </tr>
        {volist name="user" id="v_user"}
            <tr class="user_class user_{$v_user.id}" data-id="{$v_user.id}">
                <td class="layui-td-gray">{$v_user.year}-{$v_user.month}</td>
                <td class="layui-td-gray">{$v_user.name}</td>
                <td class="layui-td-gray">{$v_user.work_hours}</td>
                <td class="{$v_user.id}_td">
                    <input type="number" name="wages" data-id="{$v_user.id}"    lay-reqText="请输入工资" autocomplete="off" placeholder="请输入工资"
                           class="layui-input work work_{$v_user.id}" value="{$v_user.wages}">
                </td>
                <td class="{$v_user.id}_td">
                    <input type="number" name="accumulation_fund" data-id="{$v_user.id}"    lay-reqText="请输入社保" autocomplete="off" placeholder="请输入社保"
                           class="layui-input work accumulation_{$v_user.id}" value="{$v_user.accumulation_fund}">
                </td>
                <td class="{$v_user.id}_td">
                    <input type="number" name="social" data-id="{$v_user.id}"   lay-reqText="请输入公积金" autocomplete="off" placeholder="请输入公积金"
                           class="layui-input work social_{$v_user.id}" value="{$v_user.social}">
                </td>
            </tr>
        {/volist}
        <input type="hidden" name="year" value="{$_GET.year}">
        <input type="hidden" name="month" value="{$_GET.month}">
    </table>
    <div class="py-3">
	   <input type="hidden" name="scene" value="add">
      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>


    const moduleInit = ['tool','employeepicker',];

	function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form,laydate = layui.laydate;
        laydate.render({
            elem: "#layui-input-time",
            type: "month",
            id: 'layui-input-time',
            autoConfirm: true,
            done:function(value, date, endDate){
                console.log(value); // 日期字符，如： 2017-08-18
                console.log(date); // 包含年月日时分秒各项值的对象
                console.log(endDate); // 结束日期时间对象，当设置 range 时才会返回。对象成员同上。
                // tool.sideClose(1000);
                tool.side("/home/UserWorkHours/operation?time="+value);
                return;
            }
        });

		var form = layui.form,
            tool=layui.tool,
            employeepicker = layui.employeepicker;
		
		//监听提交
		form.on('submit(webform)', function (data) {
            var inputs = $('input[name="wages"]');
            var values = [];
            inputs.each(function() {
                var id = $(this).data('id');
                console.log(id)
                let obj = new Object();
                obj[this.name] = this.value;
                obj['uid'] = $(this).data('id');
                obj['accumulation_fund'] = $('.accumulation_'+id).val();
                obj['social'] = $('.social_'+id).val();

                // 如果values对象中还没有这个name，就初始化它为一个数组
                if (!values) {
                    values = [];
                }
                console.log(obj)
                // 将value添加到对应的数组中
                values.push(obj);
            });

            // 将对象转换为JSON字符串
            var wages = JSON.stringify(values);

            data.field['wages'] = wages;

			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/home/Wages/operation", data.field, callback);
			return false;
		});

        var form = layui.form,
            tool=layui.tool,
            oaTool=layui.oaTool,
            laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#time',
            type: 'month',
            format: 'yyyy-MM',
            showBottom: false
        });

    }
</script>
{/block}
<!-- /脚本 -->